<?php

namespace app\uapi\middleware;

use app\common\service\UserService;
use think\Exception;
use think\facade\Request;

class TokenToUser
{
    public function handle($request, \Closure $next)
    {
        try {

            $request->userInfo = [];
            $userinfo = UserService::checkOpenidBindUser();
            if ($userinfo ) {
                $request->userInfo =  $userinfo;
            }

        } catch (\Exception $err) {
            return json(['errno' => 401, 'message' => '请先登录2' .$err->getMessage()]);
        }

        return $next($request);
    }
}